from django.db import models

# Create your models here.

class SiteName(models.Model):#网站名
    
    name = models.CharField(max_length=50)
    url = models.URLField(max_length=500, unique = True)#网站域名
    #instrument = models.CharField(max_length=100)



    def __str__(self):

        return self.name


class FilmType(models.Model):#电影类型

    film_type = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.film_type
    

class Director(models.Model):#导演

    name = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.name


class Actor(models.Model):#演员

    name = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.name


class State(models.Model):#拍摄国家

    name = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.name


class Language(models.Model):#语言

    name = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.name

class ReleaseState(models.Model):#上映国家
    

    name = models.CharField(max_length=50, unique = True)

    def __str__(self):

        return self.name

    


    

class Film(models.Model):#电影

    #name = models.ForeignKey(FilmName, on_delete=models.CASCADE)
    
    director = models.ManyToManyField(Director)

    actor = models.ManyToManyField(Actor)

    state = models.ManyToManyField(State)

    release_state = models.ManyToManyField(ReleaseState, through = 'ReleaseTime')#多多关系抛出

    site_name = models.ManyToManyField(SiteName, through = 'FilmInSite')#多多关系抛出

    film_type = models.ManyToManyField(FilmType)

    intro = models.TextField()

    language = models.ManyToManyField(Language)#语言

class FilmName(models.Model):#电影名称

    name = models.CharField(max_length=50, unique = True)#电影名称

    film = models.ForeignKey(Film, on_delete=models.CASCADE)

    def __str__(self):

        return self.name





    

class FilmInSite(models.Model):#Film和SiteName多多关系表

    film = models.ForeignKey(Film, on_delete=models.CASCADE)

    site_name = models.ForeignKey(SiteName, on_delete=models.CASCADE)

    

class ReleaseTime(models.Model):#Film和ReleaseState多多关系表

    film = models.ForeignKey(Film, on_delete=models.CASCADE)

    release_state = models.ForeignKey(ReleaseState, on_delete=models.CASCADE)

    release_time = models.DateTimeField()
    

class FilmUrl(models.Model):#电影播放链接

    film_in_site = models.ForeignKey(FilmInSite, on_delete=models.CASCADE)#一对多关联FilmInSite

    url = models.URLField(max_length=500, unique = True)

    name = models.CharField(max_length=50)#表示链接为第几集

    layout = models.CharField(max_length=50)#链接的播放类型

    click_count = models.IntegerField(default = 0)#链接的点击量

    status = models.BooleanField(null = True, blank = True, default = None)#链接是否可以播放

    write_time = models.DateTimeField(auto_now_add = True)#第一次链接写入的时间

class KeywordCount(models.Model):#记录关键字的搜索情况

    time = models.DateField()
    keyword = models.CharField(max_length = 50)
    count = models.IntegerField(default = 0)


 




    
    

    

    

    

    

    




































    

    
